/*
 * Gavin Greene
 */
package businessRule;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import parsers.ScheduleParser;

import user.User;

import data.ClassSlot;
/**
 * @author Gavin Greene
 * @version 6/1/2011
 * Checks the Max credit load of a teacher against the assigned credit load
 * 
 */
public class TeacherMaxCreditLoad extends BizRule {

	List<User> myTeachers;

	Map<User, Integer> teachersViolated;
	
	public TeacherMaxCreditLoad(List<User> theTeachers){
		myTeachers = theTeachers;
		teachersViolated = new HashMap<User, Integer>();

	}
	/**
	 * Checks the rule of the class. 
	 */
	@Override
	public void CheckRule(
			List<ClassSlot> theSchedule,
			Collection<BusinessRuleViolation> BusinessRulesViolated) {
		
		teachersViolated.clear();
		
		/* for each teacher that provided feedback: */
		for (User teacher : myTeachers){
			
			int credits = 0;
			int requestedCredits = teacher.getMyMaxCredits();
			/* for each course on the schedule, count the credit hours */
			for(ClassSlot course: theSchedule){
				if(course.getClassTeacher().equals(teacher.getName()) && (course.getClassTeacher() != ScheduleParser.TBA)){
					/* if the teacher is teaching that course */
					credits = credits + course.getClassCredits();
				}
			}
			if(credits > requestedCredits ){
				if( ! (teachersViolated.containsKey(teacher)) ){
					//the teacher isn't yet in the map
					BusinessRulesViolated.add(new BusinessRuleViolation(teacher.getName(), this));
				}
				teachersViolated.put(teacher, credits);
			}
		}
	}

	@Override
	public String getName() {
		return "Teacher assigned more than maximum requested credit load";
	}
	
	public Map<User, Integer> getViolatedTeachers(){
		return teachersViolated;
	}
	

}
